package com.study.bookstore.repository;

import com.study.bookstore.domain.Author;
import com.study.bookstore.domain.BookBasic;
import com.study.bookstore.domain.BookType;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Repository;

import org.springframework.data.jpa.repository.*;


/**
 * Spring Data JPA repository for the BookBasic entity.
 */
@SuppressWarnings("unused")
@Repository
public interface BookBasicRepository extends JpaRepository<BookBasic, Long> {

    @Query("SELECT a FROM BookBasic a\n" +
        "WHERE (0=?1 or a.bookTypeId.id=?1) and (a.author LIKE CONCAT('%',?2,'%')or a.bookName LIKE CONCAT('%',?2,'%'))  ORDER BY a.bookName ")
    Page<BookBasic> findBookBasicLike(Integer type,String keyword , Pageable pageable);

    Page<BookBasic> findBookBasicsByBookTypeIdOrderByIdDesc(BookType bookType, Pageable pageable);

    Page<BookBasic> findBookBasicsByAuthodIdOrderByIdAsc(Author author, Pageable pageable);


}
